package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.vo.CodeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysTenderMapper;
import com.ruoyi.system.domain.SysTender;
import com.ruoyi.system.service.ISysTenderService;

/**
 * 招标信息Service业务层处理
 *
 * @author ruoyi
 * @date 2025-08-27
 */
@Service
public class SysTenderServiceImpl implements ISysTenderService {
    @Autowired
    private SysTenderMapper sysTenderMapper;

    /**
     * 查询招标信息
     *
     * @param tenderId 招标信息主键
     * @return 招标信息
     */
    @Override
    public SysTender selectSysTenderByTenderId(Long tenderId) {
        return sysTenderMapper.selectSysTenderByTenderId(tenderId);
    }

    /**
     * 查询招标信息列表
     *
     * @param sysTender 招标信息
     * @return 招标信息
     */
    @DataScope(deptAlias = "d", userAlias = "u")
    @Override
    public List<SysTender> selectSysTenderList(SysTender sysTender) {
        return sysTenderMapper.selectSysTenderList(sysTender);
    }

    /**
     * 新增招标信息
     *
     * @param sysTender 招标信息
     * @return 结果
     */
    @Override
    public int insertSysTender(SysTender sysTender) {
        sysTender.setCreateTime(DateUtils.getNowDate());
        sysTender.setUserId(SecurityUtils.getUserId());
        sysTender.setDeptId(SecurityUtils.getDeptId());
        return sysTenderMapper.insertSysTender(sysTender);
    }

    /**
     * 修改招标信息
     *
     * @param sysTender 招标信息
     * @return 结果
     */
    @Override
    public int updateSysTender(SysTender sysTender) {
        sysTender.setUpdateTime(DateUtils.getNowDate());
        return sysTenderMapper.updateSysTender(sysTender);
    }

    /**
     * 批量删除招标信息
     *
     * @param tenderIds 需要删除的招标信息主键
     * @return 结果
     */
    @Override
    public int deleteSysTenderByTenderIds(Long[] tenderIds) {
        return sysTenderMapper.deleteSysTenderByTenderIds(tenderIds);
    }

    /**
     * 删除招标信息信息
     *
     * @param tenderId 招标信息主键
     * @return 结果
     */
    @Override
    public int deleteSysTenderByTenderId(Long tenderId) {
        return sysTenderMapper.deleteSysTenderByTenderId(tenderId);
    }


    @Override
    public AjaxResult listSelects() {

        List<CodeVo> result = new ArrayList<>();

        List<SysTender> list = sysTenderMapper.selectSysTenderList(null);

        result = list.stream().map(c -> {

            CodeVo codeVo = new CodeVo();
            codeVo.setLabel(c.getSubTenderName());
            codeVo.setValue(c.getTenderId());

            return codeVo;
        }).collect(Collectors.toList());

        return AjaxResult.success(result);
    }
}
